package mq.rabbitmq.a_work_queue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import mq.rabbitmq.ConnectionUtil;
import mq.rabbitmq.MqConstants;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 工作队列模式：生产者
 *
 * @author shanzhenbo
 */
public class Send {


	public static void main(String[] args) throws IOException, TimeoutException {
		//获取链接
		Connection connection = ConnectionUtil.getConnection();
		//获取通道
		Channel channel = connection.createChannel();
		//声明（创建）队列
		channel.queueDeclare(MqConstants.QUEUE_NAME, false, false, false, null);

		String message = "Hello World!";
		channel.basicPublish("", MqConstants.QUEUE_NAME, null, message.getBytes());
		System.out.println("[x] send '" + message + "'");
		//关闭通道和连接
		channel.close();
		connection.close();
	}

}
